/**
 * 
 */
package org.ko.core.domain.auth;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.ko.core.domain.support.TimeEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;


/**
 * User
 * 
 * @author yangfuming
 * @date 2013-2-17
 */
@Entity
@Table(name = "SYS_USER")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class User extends TimeEntity{
	private static final long serialVersionUID = -3121144966405292283L;
	private String name;
	private String userNo;// 用户编号，自动生成
	private String password;
	private String email;// 发邮件
	private String mobilephone;// 发短信
	private char isValid;// 状态,0有效 1无效
	private char isAdmin;// 是否是管理员,0是 1否
	
	private String role;//角色名称
	
	private String remark;
	
	private List<Role> roles;
	
	@ManyToMany(cascade={CascadeType.PERSIST,CascadeType.REFRESH,CascadeType.MERGE}, fetch = FetchType.LAZY)
	@JoinTable(name = "SYS_USER_ROLE", 
			joinColumns = { @JoinColumn(name = "user_id", updatable = false) }, 
			inverseJoinColumns = { @JoinColumn(name = "role_id", updatable = false) })
	public List<Role> getRoles() {
		return roles;
	}
	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	public User(Long userId) {
		this.setId(userId);
	}
	public User() {
	    
	}
	
	@Lob
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	@Column(name = "USERNO", length = 8, unique = true, nullable = false)
	public String getUserNo() {
		return userNo;
	}

	public void setUserNo(String userNo) {
		this.userNo = userNo;
	}
	@Column(name = "NAME", length = 24, nullable = false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@JsonIgnore
	@Column(name = "PASSWORD", length = 64, nullable = false)
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	@Column(name = "EMAIL", length = 64)
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}
	@Column(name = "mobilephone", length = 11)
	public String getMobilephone() {
		return mobilephone;
	}
	public void setMobilephone(String mobilephone) {
		this.mobilephone = mobilephone;
	}
	@Column(name = "ISVALID", length = 1)
	public char getIsValid() {
		return isValid;
	}

	public void setIsValid(char isValid) {
		this.isValid = isValid;
	}
	@Column(name = "ROLE", length = 64)
	public String getRole() {
		return role;
	}
	public void setRole(String role) {
		this.role = role;
	}
	@Column(name = "ISADMIN", length = 1)
	public char getIsAdmin() {
		return isAdmin;
	}
	public void setIsAdmin(char isAdmin) {
		this.isAdmin = isAdmin;
	}	
	
}
